Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
How to fix the graphing line on math calculator with initial scale [Resolved]

Im currently building an math graphing calculator in discord.js, the graphing work fine on 1.0x scale but when im changing the scale the graphing line start not right with the axes, I saw it to be move to bottom-left not to be the center of the graph

function draw(tree) {
    var i = 0;
    dx = 1 / global_scale;

    var y;
    variables.x = minX;

    var width = canvas.width;

    while (isNaN((y = eval(tree))) && i < width) {
        variables.x = minX + i * dx;
        i++;
    }

    let previousY = (y - minY) * global_scale;

    for (; i < width; i++) {
        variables.x = minX + i * dx;
        y = eval(tree);

        if (isNaN(y)) {
            console.log(`discontinuity at x = ${x}`);
            while ((y = eval(tree)) === NaN && i < width) {
                variables.x = minX + i * dx;
                i++;
            }
            previousY = (y - minY) * global_scale;
            continue;
        }

        y = (y - minY) * global_scale;

        ctx.beginPath();
        ctx.moveTo(i - 1, previousY);
        ctx.lineTo(i, y);
        ctx.lineWidth = 2;
        ctx.stroke();
        previousY = y;
    }
}```

[The graphing when i do x^2 with 0.01 initial scale][1]

[The graphing when i do sin(x) with 0.01 initial scale][2]


and i wanna it to be something like this :
[The graphing when i do x^2 with 1.0 initial scale][3]


  [1]: https://i.stack.imgur.com/WTTl6.png
  [2]: https://i.stack.imgur.com/8fH4n.png
  [3]: https://i.stack.imgur.com/hefWl.png
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda